local skel = fk.CreateSkill {
  name = "emo__xunfen",
}

Fk:loadTranslationTable{
  ["emo__xunfen"] = "迅奋",
  [":emo__xunfen"] = "出牌阶段限一次，你可以将一张牌当做不计次数的冰【杀】使用，结算后，若上一次离开角色区域的牌含装备牌，重置此技能。",

  ["#emo__xunfen"] = "将一张牌当做不计次数的冰【杀】使用",

  ["$emo__xunfen1"] = "众将官，短刀出鞘。",
  ["$emo__xunfen2"] = "短兵轻甲也可取汝性命！",
  ["$emo__xunfen3"] = "取封侯爵赏，正在今日！",
  ["$emo__xunfen4"] = "给我拉过来！",
}

skel:addEffect("viewas", {
  anim_type = "drawcard",
  prompt = "#emo__xunfen",
  card_num = 1,
  pattern = "slash",
  mute_card = true,
  audio_index = {1, 2},
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("ice__slash")
    c.skillName = skel.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function (self, player, use)
    use.extraUse = true
  end,
  after_use = function (self, player, use)
    if player.dead then return end
    local room = player.room
    local ok = false
    room.logic:getEventsByRule(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from then -- 离开角色区域！
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).type == Card.TypeEquip then
              ok = true
              break
            end
          end
          return true
        end
      end
    end, 1)
    if ok then
      player:broadcastSkillInvoke(skel.name, math.random(3, 4))
      player:setSkillUseHistory(skel.name, 0, Player.HistoryPhase)
    end
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = function (self, player, response)
    return player.phase == Player.Play and not response
    and player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
})

skel:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, skel.name)
  end,
})

return skel
